using System.ComponentModel.DataAnnotations;

namespace AdminSG3L.Domain.Entities;

/// <summary>
/// 文章实体
/// </summary>
public class AppArticle : EntityBase
{
    /// <summary>
    /// 文章标题，必填
    /// </summary>
    public string Title { get; private set; }
    /// <summary>
    /// 文章内容，必填
    /// </summary>
    public string Content { get; private set; }
    /// <summary>
    /// 文章状态，必填
    /// </summary>
    public string Status { get; private set; }
    /// <summary>
    /// 作者，可选
    /// </summary>
    public string? Author { get; private set; }
    /// <summary>
    /// 所属分类Id
    /// </summary>
    public Guid CategoryId { get; private set; }
    /// <summary>
    /// 所属分类
    /// </summary>
    public AppArticleCategory? Category { get; private set; }
    /// <summary>
    /// 发布时间，可选
    /// </summary>
    public DateTime? PublishedDate { get; private set; }

    /// <summary>
    /// 私有构造函数，仅限工厂方法调用
    /// </summary>
    private AppArticle(string title, string content, string status)
    {
        Title = title;
        Content = content;
        Status = status;
    }

    /// <summary>
    /// 创建AppArticle对象的工厂方法
    /// </summary>
    /// <param name="title">标题</param>
    /// <param name="content">内容</param>
    /// <param name="status">状态</param>
    /// <param name="author">作者</param>
    /// <param name="category">分类</param>
    /// <param name="publishedDate">发布时间</param>
    /// <param name="description">描述</param>
    /// <returns>AppArticle对象</returns>
    public static AppArticle Create(string title, string content, string status, string? author = null, Guid? categoryId = null, DateTime? publishedDate = null, string? description = null)
    {
        return new AppArticle(title, content, status)
        {
            Author = author,
            CategoryId = categoryId ?? Guid.Empty,
            PublishedDate = publishedDate,
            Description = description
        };
    }
}
